﻿using System;
using System.Collections.Generic;
using System.Web;
using DataAccess;
using System.Data;

/// <summary>
/// Summary description for NewsBS
/// </summary>
public class NewsBS 
{
    NewsDAO news;

    public NewsBS()
    {
        //
        // TODO: Add constructor logic here
        //
        news = new NewsDAO();
    }
    // hiển thị news
    public List<News> ShowNews()
    {
        DataTable tbl = news.ShowNews();
        List<News> list = new List<News>();
        foreach (DataRow row in tbl.Rows)
        {
            News n = new News(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()));
            list.Add(n);
        }
        return list;
    }
    // hiển thị chi tiết của news 
    public List<News> ShowNewsDetails(int codenews)
    {
        DataTable tbl = news.ShowNewsDetails(codenews);
        List<News> list = new List<News>();
        foreach (DataRow row in tbl.Rows)
        {
            News n = new News(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()));
            list.Add(n);
        }
        return list;
    }
    // nấy ra code của news
    public int Codenews(string title)
    {
        int code = news.CodeNews(title);
        return code;
    }
    // thêm tin tức mới
    public void AddNews(string title, string contentSummary, string content, string imageNews)
    {
        news.InertNews(title, contentSummary, content, imageNews);
    }
    // hiển thị tin tức bên trang admin 
    public List<News> NewsAdmin()
    {
        DataTable tbl = news.NewsAdmin();
        List<News> list = new List<News>();
        foreach (DataRow row in tbl.Rows)
        {
            News n = new News(int.Parse(row[0].ToString()), row[1].ToString(), DateTime.Parse(row[2].ToString()));
            list.Add(n);
        }
        return list;
    }
    //delete news 
    public void DeleteNews(int CodeNews)
    {
        news.DeleteNews(CodeNews);
    }
    // hiển thị top news 

    public List<News> ShowTopNews()
    {
        DataTable tbl = news.ShowTopNews();
        List<News> list = new List<News>();
        foreach (DataRow row in tbl.Rows)
        {
            News n = new News(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()));
            list.Add(n);
        }
        return list;
    }
    // hiển thị top newtitle
  
    public List<News> ShowTopNewsTitle()
    {
        DataTable tbl = news.ShowTopNewsTitlte();
        List<News> list = new List<News>();
        foreach (DataRow row in tbl.Rows)
        {
            News n = new News(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()));
            list.Add(n);
        }
        return list;
    }
    // sử lý mới sự kiện 

    public List<EventsBS> ShowTopEvent()
    {
        DataTable tbl = news.ShowTopEvent();
        List<EventsBS> list = new List<EventsBS>();
        foreach (DataRow row in tbl.Rows)
        {
            EventsBS n = new EventsBS(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()), DateTime.Parse(row[6].ToString()), DateTime.Parse(row[7].ToString()));
            list.Add(n);
        }
        return list;
    }
    public List<EventsBS> ShowEvent()
    {
        DataTable tbl = news.ShowEvent();
        List<EventsBS> list = new List<EventsBS>();
        foreach (DataRow row in tbl.Rows)
        {
            EventsBS n = new EventsBS(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()), DateTime.Parse(row[6].ToString()), DateTime.Parse(row[7].ToString()));
            list.Add(n);
        }
        return list;
    }
    public void InertEvent(string Title, string ContentSummary, string Content, string ImageEvent, string StartTime, string TimeEnd)
    {
        news.InertEvent(Title,ContentSummary,Content,ImageEvent,StartTime,TimeEnd);
    }
    public List<EventsBS> ShowEventDetails(int codeEvent)
    {
        DataTable tbl = news.ShowEventDetails(codeEvent);
        List<EventsBS> list = new List<EventsBS>();
        foreach (DataRow row in tbl.Rows)
        {
            EventsBS n = new EventsBS(int.Parse(row[0].ToString()), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), DateTime.Parse(row[5].ToString()), DateTime.Parse(row[6].ToString()), DateTime.Parse(row[7].ToString()));
            list.Add(n);
        }
        return list;
    }
    public void DeleteEvent(int CodeEvent)
    {
        news.DeleteEvent(CodeEvent);
    }
}